<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>vue</title>
        <!-- 引入vue文件-->
		<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
	</head>
	<body>
		<div id="vue">
			
		</div>
	</body>
	<script type="application/javascript">
		var vm=new Vue({
			el:'#vue',
			data:{
				a:'',
				b:2,
				c:{
					name:'houzheng',
					age:23
				}
			},/*监听数据变化*/
			watch:{
				a:function(val,oldVal){
					alert(val);
				},
				c:{/*回调函数(新值,旧值)*/
					handler:function(val,oldVal){
						alert('哈哈')
					},
					deep:true  //监听深度变化,对象引用的改变
				}
			}
		});
		vm.$watch('b',function(val,oldVal){
			alert('新值:'+val+', '+"原来的值:"+oldVal)
		});
		document.onclick=function(){
			vm.b=5;
			vm.c.age=24;
			vm.a='yaozhen';
		}
	</script>
</html>
